#pragma once

#include "../widgets.h"
#include "basechart_painter.h"
#include "basechart_vector2d.h"

class S_WIDGETS_EXPORT BaseChartLineEnding {
  Q_GADGET
 public:
  /*!
    Defines the type of ending decoration for line-like items, e.g. an arrow.

    \image html BaseChartLineEnding.png

    The width and length of these decorations can be controlled with the
    functions \ref setWidth and \ref setLength. Some decorations like \ref
    esDisc, \ref esSquare, \ref esDiamond and \ref esBar only support a width,
    the length property is ignored.

    \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead,
    QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
  */
  enum EndingStyle {
    esNone  ///< No ending decoration
    ,
    esFlatArrow  ///< A filled arrow head with a straight/flat back (a triangle)
    ,
    esSpikeArrow  ///< A filled arrow head with an indented back
    ,
    esLineArrow  ///< A non-filled arrow head with open back
    ,
    esDisc  ///< A filled circle
    ,
    esSquare  ///< A filled square
    ,
    esDiamond  ///< A filled diamond (45 degrees rotated square)
    ,
    esBar  ///< A bar perpendicular to the line
    ,
    esHalfBar  ///< A bar perpendicular to the line, pointing out to only one
               ///< side (to which side can be changed with \ref setInverted)
    ,
    esSkewedBar  ///< A bar that is skewed (skew controllable via \ref
                 ///< setLength)
  };
  Q_ENUMS(EndingStyle)

  BaseChartLineEnding();
  BaseChartLineEnding(EndingStyle style, double width = 8, double length = 10,
                      bool inverted = false);

  // getters:
  EndingStyle style() const { return mStyle; }
  double width() const { return mWidth; }
  double length() const { return mLength; }
  bool inverted() const { return mInverted; }

  // setters:
  void setStyle(EndingStyle style);
  void setWidth(double width);
  void setLength(double length);
  void setInverted(bool inverted);

  // non-property methods:
  double boundingDistance() const;
  double realLength() const;
  void draw(BaseChartPainter* painter, const BaseChartVector2D& pos,
            const BaseChartVector2D& dir) const;
  void draw(BaseChartPainter* painter, const BaseChartVector2D& pos,
            double angle) const;

 protected:
  // property members:
  EndingStyle mStyle;
  double mWidth, mLength;
  bool mInverted;
};

Q_DECLARE_TYPEINFO(BaseChartLineEnding, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(BaseChartLineEnding::EndingStyle)
